package net.lab1024.sa.admin.module.business.erp.mmo.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.erp.mmo.dao.MrqordaDao;
import net.lab1024.sa.admin.module.business.erp.mmo.domain.entity.MrqordaEntity;
import net.lab1024.sa.admin.module.business.erp.mmo.domain.form.MrqordaAddForm;
import net.lab1024.sa.admin.module.business.erp.mmo.domain.form.MrqordaQueryForm;
import net.lab1024.sa.admin.module.business.erp.mmo.domain.form.MrqordaUpdateForm;
import net.lab1024.sa.admin.module.business.erp.mmo.domain.vo.MrqordaVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service
public class MrqordaService {

    @Resource
    private MrqordaDao mrqordaDao;


    public PageResult<MrqordaVO> queryPage(MrqordaQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<MrqordaVO> list = mrqordaDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }




    @Transactional
    public ResponseDTO<String> add(MrqordaAddForm addForm) {
        MrqordaEntity mrqordaEntity = SmartBeanUtil.copy(addForm, MrqordaEntity.class);
        mrqordaDao.insert(mrqordaEntity);



        return ResponseDTO.ok();
    }

    public ResponseDTO<String> update(MrqordaUpdateForm updateForm) {
        MrqordaEntity mrqordaEntity = SmartBeanUtil.copy(updateForm, MrqordaEntity.class);
        mrqordaDao.updateById(mrqordaEntity);
        return ResponseDTO.ok();
    }

    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        mrqordaDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    public ResponseDTO<String> delete(Long id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        mrqordaDao.deleteById(id);
        return ResponseDTO.ok();
    }
}
